package jtg.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lobas_av
 * 
 */
public class PhoneGroups extends AbstractModelObject {

	private List<Ente> m_enti = new ArrayList<Ente>();
	private String m_name;

	public PhoneGroups() {
	}
	
	public String getName() {
		return m_name;
	}

	public void setName(String name) {
		String oldValue = m_name;
		m_name = name;
		firePropertyChange("name", oldValue, m_name);
	}


	public void addEnte(Ente e) {
		List<Ente> oldValue = m_enti;
		m_enti = new ArrayList<Ente>(m_enti);
		m_enti.add(e);
		firePropertyChange("enti", oldValue, m_enti);
		firePropertyChange("entiCount", oldValue.size(), m_enti.size());
	}

	public void removeEnte(Ente e) {
		List<Ente> oldValue = m_enti;
		m_enti = new ArrayList<Ente>(m_enti);
		m_enti.remove(e);
		firePropertyChange("enti", oldValue, m_enti);
		firePropertyChange("entiCount", oldValue.size(), m_enti.size());
	}

	public List<Ente> getEnti() {
		return m_enti;
	}
	
	public int getPersonCount() {
		return m_enti.size();
	}

	public void aggiorna() {
		List<Ente> oldValue = m_enti;
		ArrayList<Ente> m_entiTmp = new ArrayList<Ente>();
		for(int i=0;i<m_enti.size();i++)
			m_entiTmp.add(m_enti.get(i));
		m_enti.removeAll(oldValue);
		for(int i=0;i<m_entiTmp.size();i++)
			this.addEnte(m_entiTmp.get(i));
	}

	public void removeAll() {
		m_enti=new ArrayList<Ente>();
	}
}